#ifndef CUSTOMMODEL_H
#define CUSTOMMODEL_H

#include <QList>
#include <QAbstractItemModel>
#include "TreeItem.h"

class CustomModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    explicit CustomModel(QObject *parent = nullptr);

    void fun_setHeaderData(QStringList names);
    void fun_addDataRow(_DATA_STRUCT data);
    void fun_clearData();
    void fun_HederInit();
    _DATA_STRUCT fun_GetDataItem(QModelIndex index);
    QList<_DATA_STRUCT> fun_GetListAll();

    /**
     * rowCount
     * 视图会从这里数据并刷新
     * 获取行数
     * */
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    /**
     * rowCount
     * 视图会从这里数据并刷新
     * 获取列数
     * */
    int columnCount(const QModelIndex &parent) const override;
    /**
     * data
     * 视图会从这里数据并刷新
     * QAbstractItemModel::data() 在两种情况下被触发： 1） QAbstractItemModel
     * 释放dataChanged 信号时； 2）QAbstractItemModel  调用appendRow方法时。
     * 但是 dataChanged 并不能总是触发data函数
     */
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    /**
     * setData
     * 视图会调用该函数刷新数据
     * 获取行或者列的某一项数据
     * */
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
    QModelIndex parent(const QModelIndex &child) const override;
    /**
     * headerData
     * 视图会从这里数据并刷新
     * 获取行或者列的某一项数据
     * */
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
signals:
    void sig_ModelMOdif(_DATA_STRUCT data,const QModelIndex &index);
public:

    int m_btnColumn;
private:
    //m_names列标题
    QStringList m_names;
    //行内容
    QList<_DATA_STRUCT> m_data; 
};

#endif // CUSTOMMODEL_H
